#include "platform.h"

// #pragma GCC push_options
// #pragma GCC optimize ("O0")

void Serv_BitWrite(volatile uint32_t *baseaddr ,uint8_t _pin ,uint8_t _val)  {
    *baseaddr  = (_val)? *baseaddr |(1u << _pin) : *baseaddr & ~(1u << _pin) ; 
} 

uint32_t Serv_BitRead(volatile uint32_t * baseaddr ,uint8_t _pin ) {
    return  ((*baseaddr >> _pin) & 0x1)  ;
}


void Serv_PinSet(volatile uint32_t * _port, uint8_t _pin ){
    *_port |= 1u<<_pin ;
}
void Serv_PinReset(volatile uint32_t * _port, uint8_t _pin ){
    *_port &= ~(1u<<_pin) ;
}
uint32_t Serv_PinGet(volatile uint32_t * _port, uint8_t _pin ){
    return (uint32_t)((*_port >> _pin) & 0x1) ;
}



// void Serv_DelayTik(int32_t _delay_ticks) {
//     uint8_t cnt = _delay_ticks;
//     while (cnt>0)cnt--;
// }


// void Serv_Delayms(const volatile uint32_t ms){
// 	volatile uint32_t b = TIK;
// 	while(TIK <= ms + b) ;
// }



uint32_t Serv_Tik(){
    return TIK;
}


// #pragma GCC pop_options  // 结束不优化的代码